package fr.alesia.capital.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fr.alesia.capital.bean.Pays;
import fr.alesia.capital.match.PaysFinder;
import fr.alesia.capital.match.PaysFinderUnimatch;

@SuppressWarnings("serial")
public class RechercheServlet extends HttpServlet {
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		
		ServletContext context = this.getServletContext();
		PaysFinder finder = PaysFinderUnimatch.getInstance();	
		String terms = request.getParameter("terms");
			
		Pays pays = finder.find(terms);
		
		request.setAttribute("pays", pays);
		request.setAttribute("terms", terms);
		
		RequestDispatcher dispatcher = context.getRequestDispatcher("/webapp/page/recherche.jsp");
		dispatcher.forward(request, response);
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		
		this.doPost(request, response);
	}
}
